<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateFileUploadConfigTable extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('file_upload_config', [
            'id' => true,
            'primary_key' => ['id'],
            'comment' => '文件上传配置表',
            'engine' => 'InnoDB',
            'encoding' => 'utf8mb4',
        ]);
        $table->addColumn('name', 'string', [
            'limit' => 50,
            'null' => false,
            'default' => '',
            'comment' => '配置名称',
        ])->addColumn('storage_type', 'string', [
            'limit' => 20,
            'null' => false,
            'default' => 'local',
            'comment' => '存储类型:local=本地,oss=阿里云,cos=腾讯云,qiniu=七牛云,s3=亚马逊',
        ])->addColumn('config', 'json', [
            'null' => true,
            'comment' => '存储类型特定配置(JSON格式)',
        ])->addColumn('single_limit', 'biginteger', [
            'null' => true,
            'comment' => '单个文件大小限制(字节)',
        ])->addColumn('total_limit', 'biginteger', [
            'null' => true,
            'comment' => '总文件大小限制(字节)',
        ])->addColumn('nums', 'integer', [
            'null' => true,
            'comment' => '文件数量限制',
        ])->addColumn('include', 'text', [
            'null' => true,
            'comment' => '允许的文件类型',
        ])->addColumn('exclude', 'text', [
            'null' => true,
            'comment' => '不允许的文件类型',
        ])->addColumn('remark', 'string', [
            'limit' => 255,
            'null' => true,
            'comment' => '备注',
        ])->addColumn('status', 'boolean', [
            'null' => false,
            'default' => 1,
            'comment' => '状态:0=禁用,1=启用',
        ])->addColumn('sort', 'integer', [
            'null' => false,
            'default' => 0,
            'comment' => '排序',
        ])->addColumn('create_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'comment' => '创建时间',
        ])->addColumn('update_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'update' => 'CURRENT_TIMESTAMP',
            'comment' => '更新时间',
        ])->addIndex(['name'], [
            'name' => 'idx_name',
        ])->addIndex(['storage_type'], [
            'name' => 'idx_storage_type',
        ])->create();
    }
}